import java.util.Arrays;

public class Test {

    public static int[] copyOf(int[] array) {
        int[] ret = new int[array.length];
        for (int i = 0; i < array.length; i++) {
            ret[i] = array [i];
        }
        return ret;
    }

    public static void main(String[] args) {
        int[] array= {0,2,3,4,7,8,10};
        int[] ret = copyOf(array);
        array[0] = 99;
        System.out.println(Arrays.toString(array));
        System.out.println(Arrays.toString(ret));
    }

    public static int binarySearch(int[] array,int n) {
        int left = 0;
        int right = array.length-1;
        while (left <= right) {
            int mid = left + (right-left) / 2;
            if (array[mid] > n) {
                right = mid-1;
            }else if (array[mid] < n) {
                left = mid+1;
            }else  {
                return mid;
            }
        }
        return -1;
    }

    public static void main9(String[] args) {
        int[] array= {0,2,3,4,7,8,10};
        System.out.println(binarySearch(array, 8));
        System.out.println(binarySearch(array, 5));
    }

    public static boolean isOrder(int[] array) {
        boolean flg =true;
        for (int i = 0; i < array.length; i++) {
            for (int j = array.length-1; j > 0; j--) {
                if (array[j] < array[j-1]) {
                    flg = false;
                }
            }
        }
        return flg;
    }

    public static void main8(String[] args) {
        int[] array= {0,2,3,4,7,8};
        System.out.println(isOrder(array));
    }

    public static void bubbleSort(int[] array) {
        for (int i = 0; i < array.length-1; i++) {
            boolean flg = false;
            for (int j = 0; j < array.length-1-i; j++) {
                if (array[j] > array[j+1]) {
                    swap(array,j,j+1);
                    flg = true;
                }
            }
            if (flg == false) {
                break;
            }
        }
    }

    public static void main7(String[] args) {
        int[] array = {6,5,4,3,2,1};
        bubbleSort(array);
        System.out.println(Arrays.toString(array));
    }

    public static void main6(String[] args) {
        int[] array = new int[100];
        for (int i = 0; i < array.length; i++) {
            array[i] = i+1;
        }
        printArray(array);
    }

    public static void printArray(int[] array) {
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i]+" ");
        }
    }

    public static void main5(String[] args) {
        int[] array = {1,2,3,4,5,6};
        printArray(array);
    }

    public static int[] transform(int[] array) {
        for (int i = 0; i < array.length; i++) {
            array[i] = array[i]*2;
        }
        return array;
    }

    public static void main4(String[] args) {
        int[] array = {1,2,3,4,5,6};
        System.out.println(Arrays.toString(transform(array)));
    }

    public static int sum(int[] array) {
        int sum = 0;
        for (int i = 0; i < array.length; i++) {
            sum += array[i];
        }
        return sum;
    }

    public static void main3(String[] args) {
        int[] array = {1,2,3,4,5,6};
        System.out.println(sum(array));
    }

    public static double avg(int[] array) {
        double ret = 0.0;
        for (int i = 0; i < array.length; i++) {
            ret += array[i];
        }
        return ret / array.length;
    }

    public static void main2(String[] args) {
        int[] array = {1,2,3,4,5,6};
        System.out.println(avg(array));
    }

    public static void swap(int[]array,int i,int j) {
        int tmp = array[i];
        array[i] = array[j];
        array[j] = tmp;
    }

    public static int[] func1(int[] array) {
        int left = 0;
        int right = array.length-1;
        while (left < right) {
            swap(array,left,right);
            left++;
            right--;
        }
        return array;
    }

    public static void main1(String[] args) {
        int[] array1 = {1,2,3,4,5,6};
        int[] array2 = {1,3,5,7,9};
        System.out.println(Arrays.toString(func1(array1)));
        System.out.println(Arrays.toString(func1(array2)));
    }

}
